﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enlightener.Engine.Utils;
using Mono.Cecil;

namespace Enlightener.Engine.Structs__Enums___Interfaces
{
    public abstract class IDeobfuscator
    {
        public AssemblyDefinition AsmDef;
        public List<DeobfuscationTask> TaskQueue = new List<DeobfuscationTask>();
        public bool IsSave = true;

        private DateTime _startTime;

        protected IDeobfuscator(AssemblyDefinition asmDef)
        {
            AsmDef = asmDef;

            CreateTaskQueue();
        }

        public abstract void CreateTaskQueue();

        public void Deobfuscate()
        {
            _startTime = DateTime.Now;

            foreach (var task in TaskQueue)
            {
                Logger.VSLog("\nPerforming routine: " + task.RoutineDescription);
                task.PerformTask();

            }

            Logger.VSLog(string.Format("\nObfuscated assembly saved at: {0}", DeobfuscatorContext.OutPath));

            if (IsSave)
                Save(DeobfuscatorContext.OutPath);
        }

        public void Save(string path)
        {
            AsmDef.Write(path);
        }
    }
}
